package com.hqyj.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class EmailUtil {
    //注入邮件发送类
    @Autowired
    JavaMailSender javaMailSender;


    public HashMap<String,Object> sendEmail(String email,String content,String title){
        HashMap<String,Object> map = new HashMap<>();
        try{
            //创建一个邮件
            SimpleMailMessage message = new SimpleMailMessage();
            //收件人
            message.setTo(email);
            //发送人
            message.setFrom("lianpeng19981030@163.com");
            //邮件标题
            message.setSubject(title);
            //邮件正文
            message.setText(content);

            //发送邮件
            javaMailSender.send(message);
            map.put("info","发送成功");
        }catch (Exception e){
            e.printStackTrace();
            map.put("info","发送失败");
        }
        return map;
    }
}
